package com.testing.hibernateapp.tapestry.services;

import org.apache.tapestry5.*;
import org.apache.tapestry5.hibernate.HibernateTransactionDecorator;
import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.Match;

import com.testing.hibernateapp.service.UniversalHibernateDAO;
import com.testing.hibernateapp.service.UniversalHibernateDAOImpl;

public class AppModule {
	public static void bind(ServiceBinder binder) {
		binder.bind(UniversalHibernateDAO.class,
				UniversalHibernateDAOImpl.class);
	}

	public static void contributeApplicationDefaults(
			MappedConfiguration<String, String> configuration) {
		configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en");
		configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
		configuration.add(SymbolConstants.APPLICATION_VERSION, "1.0-SNAPSHOT");
	}

	public static void contributeHibernateEntityPackageManager(
			Configuration<String> configuration) {
		configuration.add("com.testing.hibernateapp.beans");
	}

	@Match("*DAO")
	public static <T> T decorateTransactionally(
			HibernateTransactionDecorator decorator, Class<T> serviceInterface,
			T delegate, String serviceId) {
		return decorator.build(serviceInterface, delegate, serviceId);
	}
}
